from deck import Deck
from player import Player


class Game:
    def __init__(self):
        p1 = "p1"
        p2 = "p2"
        # INIT DECK
        self.deck = Deck()
        # INIT PLAYER 1 and 2
        self.p1 = Player(p1, None, 0)
        self.p2 = Player(p2, None, 0)

    def start_game(self):
        cards = self.deck.cards
        print("Beginning the War game")
        while len(cards) >= 2:
            res = input("q to quit, any other key to play.")
            if res == 'q':
                break
            p1_card = self.deck.fetch()
            p2_card = self.deck.fetch()
            print("{} drew {} while {} drew {}".format(self.p1.name, p1_card, self.p2.name, p2_card))
            if p1_card > p2_card:
                self.p1.wins += 1
                print("\t" * 12 + "{} wins this round... total {} wins".format(self.p1.name, self.p1.wins))
            elif p1_card < p2_card:
                self.p2.wins += 1
                print("\t" * 24 + "{} wins this round... total {} wins".format(self.p2.name, self.p2.wins))

        print("The War Game is over. {} wins".format(self.get_winner(self.p1, self.p2)))

    def get_winner(self, p1, p2):
        if p1.wins > p2.wins:
            return p1.name
        if p2.wins < p2.wins:
            return p2.name
